package org.csmzxy.class2333;
class AgeIllegalException extends Exception{
    public AgeIllegalException(String message){
        super(message);
    }
}
public class example26 {
    //定义一个保存年龄的方法saveAge()
    public static void saveAge(int age) throws AgeIllegalException {
        if (age > 0 && age < 150) {
            System.out.println("年龄被成功保存：" + age);
        } else {
            //抛出AgeIllegalException类型的异常
            throw new AgeIllegalException("您输入的年龄不合法！");
        }
    }

    public static void main(String[] args) {
        try {
            saveAge(225);  //调用saveAge()方法
        } catch (AgeIllegalException e) {
            System.out.println(e.getMessage());
        }
    }
}
